package com.sm.honkon.ui.model

import androidx.lifecycle.asLiveData
import au.com.safie.user.app.util.CacheUtil
import com.blankj.utilcode.util.ToastUtils
import com.sm.honkon.app.App
import com.sm.honkon.data.bean.HandlerEntity
import com.sm.honkon.data.bean.UserInfo
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField

class SignUseLoginViewModel:BaseViewModel() {
    val admin: UserInfo? = CacheUtil.getUser()
    val mobile = StringObservableField()
    val password = StringObservableField()

    fun login(function: () -> Unit) {
        val mobile = mobile.get()
        val password = password.get()
        if (mobile.isEmpty()) {
            ToastUtils.showShort("请输入手机号/工号")
            return
        }
        if (password.isEmpty()) {
            ToastUtils.showShort("请输入密码")
            return
        }
        admin?.let {
            if (it.password != password || it.mobile != mobile) {
                ToastUtils.showShort("账号或密码不正确")
            } else {
                function.invoke()
            }
        }
    }

}